<div id="postid" class="form-comment-wrap large-12 columns">
<div class="heads large-12 column">
<div class="headpost large-12 column">
	<ul class="inline-list">
		<li class="cht"><img src="<?= BASE_URI ?>img/icons/chat.png">
			<a>
				&nbsp;&nbsp;Status Updates&nbsp;&nbsp;&nbsp;|
			</a>
		</li>
		<input type="file" accept = "image/*" id="upload" name="upload" style="visibility: hidden; width: 1px; height: 1px" multiple />
		<li class="cam"><img src="<?= BASE_URI ?>img/icons/cam.png">
			<a id="btnUpload">
				&nbsp;&nbsp;Upload Photo
			</a>
		</li>
		<li id="postLoading" class="right"><img src="<?= BASE_URI ?>img/loading.gif"></li>

	</ul>
</div>
</div>
	<div class="text-area large-12 columns">
		<textarea class="textarea-xpnd" id="info" placeholder="What's in your mind?"></textarea>
		
	</div>
	<div id="out">
	</div>
	
	<div class="large-12 columns">
		<a id="btnPost" class="postbutton right radius button">Post</a>
	</div>
</div>


 <script type="text/javascript">
 $(document).on('change','#upload',function(){

 });
 $('#btnUpload').click(function(){ 	
 	$('#upload').click();
 });

 /*$('#info').on("input",function(){		
	var text = $(this).val();
	var reg = /(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/;
	if(reg.test(text)){
		$('#postLoading').show();
		$.ajax({
			url: URL + 'feeds/convert',
			data: {text:text},
			type: 'get',
			dataType: 'json',
			success: function(data){
				if(data.status == true)
				{	
					$('#out').html(data.html);	
					$('#postLoading').hide();
				}
			}
		});
	}
});  

 */

$('#btnPost').click(function(){
	
	var comments = $('#info').val().replace(/(<([^>]+)>)/ig,"");
	if(comments.trim() == '') return false;
	var html = $('#out').html();
	$('#postLoading').show();
	$.ajax({
		url: URL + 'feeds/insert',
		type: 'post',
		dataType: 'json',
		data: {content:Linkify(comments),html:html,receiver:"<?= $_GET['bhd'] ?>"},
		success: function(result){
			if(result.status == false){
				alert(result.messages);
			}else if(result.status == true){
				
			}
				$('#info').val('');
				$('#out').html('');
				$('#postLoading').hide();
		}
	});
	
	return false;
});

jQuery(document).ready(function() {
  		jQuery("abbr.timeago").timeago();
});

$(document).on('keypress','.commentbox',function(e) {
	
	  if(e.which == 13)
	  {
	  	 var comment = $(this).val();
	  	 var feed_id = $(this).attr('id');
	  	 var receiver_id = $(this).attr('receiver-id'); //for notification
	  	 var sender_id = "<?= $this->session->get('user_id'); ?>";
	  	 
	  	 if(!$.trim(comment) == '')
	  	 {
	  	 	$.ajax({
	  	 		url: URL + 'comments/insert',
	  	 		type: 'post',
	  	 		data:{comments:comment,feed_id:feed_id,receiver_id:receiver_id,sender_id:sender_id},
	  	 		dataType: 'json',
	  	 		success: function(result){
	  	 			if(result.status == true)
	  	 			{
	  	 				
	  	 			}
	  	 			else
	  	 			{
	  	 				//alert(result.messages);
	  	 			}
	  	 		}	
	  	 	})
	  	 }
	  	 $(this).val('');
	  	 $('.commentbox').blur();
	  }

});
 </script>

<script>
	var count= 1;
	var chars= 67;
		$('.textarea-xpnd').keydown(function() {
		        var v = $(this).val();
		        var vl = v.replace(/(\r\n|\n|\r)/gm,"").length;   
		    if (parseInt(vl/count) == chars) {
		        $(this).val(v + '\n');
		    count++;
		    }
		});
 </script>